exports.updatePassword = function (req, res) {

    var bodyParams = req.routeInfo.bodyParams;

    var resultData = {};

    var u_id = bodyParams.u_id;

    var oldPassword = bodyParams.oldPassword;

    var newPassword = bodyParams.newPassword;

    function searchUserInfoAndCheckPassword(cb) {

        R.SEND_HTTP(
            req,
            res,
            {
                url: CORE_APIConfig.coreAPI.userSearch.Request_Api_Url + "/u_id/" + u_id,
                method: 'POST',
                data: {
                    fields: ["u_id", "u_password"].join(",")
                }
            },
            function (data) {

                var userInfo = data.result.data;

                if (userInfo.length > 0) {
                    if (userInfo[0].u_password == oldPassword && userInfo[0].u_password != newPassword) {
                        cb()
                    }else if(userInfo[0].u_password != oldPassword){
                        return RES.errorResponse(res, "原始密码输入错误！");
                    } else if (userInfo[0].u_password == newPassword) {
                        return RES.errorResponse(res, "新密码不能与原始密码一致！");
                    }
                } else {
                    return RES.errorResponse(res, "账号异常或不存在！");
                }
            }
        )
    }

    function actionUpdate(cb) {
        R.SEND_HTTP(
            req,
            res,
            {
                url: CORE_APIConfig.coreAPI.userUpdate.Request_Api_Url,
                method: 'POST',
                data: {
                    update_where: "u_id",
                    u_id: u_id,
                    u_password: newPassword
                }
            },
            function (data) {

                resultData.updateInfo = data.success;

                cb();
            }
        )
    }

    F.Serial([searchUserInfoAndCheckPassword, actionUpdate], () => {
        RES.successResponse(res,resultData);
    })

};